﻿using NUnit.Framework;
using ProjetoComperio.BusinessLogicLayer;
using ProjetoComperio.DataLayer.Infra;
using ProjetoComperio.DataLayer.Entities;
using System;
using System.Transactions;

namespace ProjetoComperio.Test.BusinessLogicLayer
{
    [TestFixture]
    public class CommentBLLTest
    {
        CommentBLL commentBLL;
        SubjectBLL subjectBLL;

        [TestFixtureSetUp]
        public void TestFixtureSetUp()
        {
            commentBLL = new CommentBLL();
            subjectBLL = new SubjectBLL();
        }

        [Test]
        public void TestValidCreate()
        {
            using (TransactionScope transactionScope = new TransactionScope())
            {
                Student student = StudentBLLTest.CreateFakeStudent();
                String password = "1234ABCD_90s";
                string UserName = "ASHD_87s";

                StudentBLL studentBLL = new StudentBLL();
                studentBLL.Create(student, UserName, password);

                 EducationalITApplication educationalItApplication = new EducationalITApplication
                {
                    AcademicPerson = student,
                    AcademicPersonID = student.PersonID,
                    Title = "title",
                    RegisterDate = DateTime.Now,
                    SourceInfo = "sourceInfo",
                    AdditionalInfo = "ai",
                    Description = "description",
                    UseInstructions = "UseInstructions",
                    IsFree = true,
                    IsOpenSource = true
                };

                EducationalITApplicationBLL educationalItApplicationBLL = new EducationalITApplicationBLL();

                educationalItApplicationBLL.Create(educationalItApplication);
                
                var subject = new Subject
                {
                    CreatedDate = DateTime.Now,
                    Message = "MessageTest",
                    Title = "TitleTest",
                    UserName = "teste@username.com.br",
                    ContributionID = educationalItApplication.ContributionID 
                };

                var subjectBLL = new SubjectBLL();
                subjectBLL.Create(subject); 
                
                var comment = new Comment
                {
                    Description = "Teste descrição",
                    CreatedDate = DateTime.Now,
                    Email = "TEste@teste.com",
                    UserName = "userNameTeste",
                    SubjectId = subject.SubjectID
                };

                commentBLL.Create(comment);
                Assert.IsNotNull(commentBLL.RetrieveComment(comment.CommentID));

                transactionScope.Dispose();
            }
        }
    }
}
